
$( document ).ready(function($) {
	$('.tools a').click(function(event){
		event.preventDefault();

		$('.alert').remove();

		var $item = $(this).closest('li');

		//bootbox.setDefaults({locale: "vi"});
		bootbox.confirm("Bạn có chắc chắn muốn xóa hình ảnh này không?", function(result) {
			if(result) {
				postAjax($webroot + 'admin/products/deleteimg', {id:$item.attr('id')}, function(resp){

					var text = resp.code === 'success' ? 'Thành công' : 'Thất bại';
					var $msg = '<div class="alert alert-'+resp.code+'"><button type="button" class="close" data-dismiss="alert" aria-hidden="true"><i class="fa fa-times"></i></button><p><strong>'+text+':</strong><br> '+resp.msg+'</p></div>';
					$item.parent().before($msg );

					if(resp.code === 'success'){
						$item.remove();
					}
				});
			}
		});
	});
});


//colorbox view Detail img
jQuery(function($) {
	var $overflow = '';
	var colorbox_params = {
		rel: 'colorbox',
		reposition:true,
		scalePhotos:true,
		scrolling:false,
		previous:'<i class="fa fa-arrow-left text-gray"></i>',
		next:'<i class="fa fa-arrow-right text-gray"></i>',
		close:'<i class="fa fa-times text-gray"></i>',
		current:'{current} of {total}',
		maxWidth:'100%',
		maxHeight:'100%',
		onOpen:function(){
			$overflow = document.body.style.overflow;
			document.body.style.overflow = 'hidden';
		},
		onClosed:function(){
			document.body.style.overflow = $overflow;
		},
		onComplete:function(){
			$.colorbox.resize();
		}
	};

	$('.tc-gallery [data-rel="colorbox"]').colorbox(colorbox_params);
	$("#cboxLoadingGraphic").append("<i class='fa fa-spinner fa-spin'></i>");//let's add a custom loading icon
});